<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Login</title>
    <link rel="stylesheet" href="static/element-ui/2.15.2/index.css">
    <style scoped>
        .login-container {
            width: 100%;
            height: 100%;
        }
        .login-page {
            -webkit-border-radius: 5px;
            border-radius: 5px;
            margin: 180px auto;
            width: 350px;
            padding: 35px 35px 15px;
            background: #fff;
            border: 1px solid #eaeaea;
            box-shadow: 0 0 25px #cac6c6;
        }
        label.el-checkbox.rememberme {
            margin: 0px 0px 15px;
            text-align: left;
        }
    </style>
</head>
<body>
<div id="login">
    <div class="login-container">
        <el-form :model="ruleForm" :rules="rules" ref="ruleForm" status-icon label-position="left" label-width="0px" class="demo-ruleForm login-page">
            <h3 class="title">登录WebShell</h3>
            <el-form-item prop="username">
                <el-input type="text" v-model="ruleForm.username" auto-complete="off" placeholder="用户名"></el-input>
            </el-form-item>
                <el-form-item prop="password">
                    <el-input type="password" v-model="ruleForm.password" auto-complete="off" placeholder="密码"></el-input>
                </el-form-item>
            <el-form-item style="width:100%;">
                <el-button type="primary" style="width:100%;" @click="login">登录</el-button>
            </el-form-item>
        </el-form>
    </div>
</div>

<script src="static/js/axios.min.js"></script>
<script src="static/js/ajax.js"></script>
<script src="static/vue/v2.6.12/vue.js"></script>
<script src="static/element-ui/2.15.2/index.js"></script>
<script>
    var app = new Vue({
        el: '#login',
        data: {
            login_url: 'http://' + document.domain + ':' + location.port + '/login',
            ruleForm: {
                username: "",
                password: ""
            },
            rules: {
                username: [
                    { required: true, message: '请输入用户名', trigger: 'blur' },
                ],
                password: [
                    { required: true, message: '请输入密码', trigger: 'blur' },
                ]
            }
        },
        methods: {
            login() {
                var _self = this;
                var params = {
                    "username": _self.ruleForm.username,
                    "password": window.btoa(_self.ruleForm.password)
                };
                ajax.post(_self.login_url, params).then(function (response) {
                    if (response.data.code === 0) {
                        _self.$message.success('登录成功！');
                        window.location.href = 'http://' + document.domain + ':' + location.port;
                    } else {
                        _self.$message.error(response.data.msg);
                    }
                }).catch(function (error) {
                    _self.$message.error(error.message);
                });
            }
        }
    })
</script>
</body>
</html>